package mil.af.amc.adpetracker.web.actions.struts1.DrmoPackage;

import mil.af.amc.adpetracker.web.actions.struts1.AbstractAction;
import mil.af.amc.adpetracker.service.DrmoPackageService;
import mil.af.amc.adpetracker.service.ServiceException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Action to edit a DRMO Package
 *
 * @author TSgt Jason Ferguson
 */

public class EditDrmoPackageAction extends AbstractAction {

    private static final Log log = LogFactory.getLog(EditDrmoPackageAction.class);

    private DrmoPackageService drmoPackageService;

    public void setDrmoPackageService(DrmoPackageService drmoPackageService) {
        this.drmoPackageService = drmoPackageService;
    }

    @Override
    public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {

        DynaActionForm form = (DynaActionForm) actionForm;

        try {
            drmoPackageService.editPackage(form.getMap());
        } catch (ServiceException e) {

            log.debug(e);
            ActionMessage message = new ActionMessage(e.getKey());
            saveError(httpServletRequest, message);

            return actionMapping.getInputForward();
        }

        return actionMapping.findForward("success");
    }
}
